<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page isELIgnored="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html style="overflow-y: visible;">
    <jsp:include page="../../../include/IncludeMain.jsp"></jsp:include>
  <body style="overflow-y: visible!important;overflow-y: scroll;">
	  <form action="${pageContext.request.contextPath }/pages/business/material.do?act=save" name="myForm" id="myForm" method="post">
	    	<table class="mainTable">
				<thead>
					<tr class="tableController">
						<th colspan="2">
							<h3>物料编辑</h3>
						</th>
					</tr>
					<tr>
						<th>&nbsp;	</th>
						<th class="errorTip" style='<c:if test="${empty message}">display:none</c:if>'>
							<c:forEach items="${message}" var="m">
								${m }
							</c:forEach>
						</th>
					</tr>
					<tr class="tableTitle">
						<th>
							<h3>&nbsp;</h3>
						</th>
						<th>
							<h3>&nbsp;</h3>
						</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="200" align="right"><h4>料号规则:&nbsp;&nbsp;</h4></td>
						<td>
							<select validation="required=1"  name="rule" id="rule" style="width:120px;" onchange="ruleSel(this);">
								<option value="">请选择</option>
								<c:forEach items="${ruleList}" var="data" varStatus="i">
									<option value="${data.id },${i.index }">${data.name }</option>
								</c:forEach>
							</select>
							<em style="color:red;">*</em>
						</td>
					</tr> 
					<tr>
						<td width="200" align="right"><h4>料号:&nbsp;&nbsp;</h4></td>
						<td>
							<input type="text" validation="required" name="material.material_id" id="materialId" value="${material.material_id}"/>
							<input type="hidden" name="material.id" id="id" value="${material.id}"/> 
							<em style="color:red;">*</em>
						</td>
					</tr> 
					<tr>
						<td align="right"><h4>属性:&nbsp;&nbsp;</h4></td>
						<td id="MyAtt">
							&nbsp;
						</td>
					</tr> 
					<tr>
						<td align="right"><h4>品名:&nbsp;&nbsp;</h4></td>
						<td>
							<input type="text" validation="required"  name="material.name" id="name" value="${material.name}"/>
							<em style="color:red;">*</em>
						</td>
					</tr> 
					<tr>
						<td align="right"><h4>描述:&nbsp;&nbsp;</h4></td>
						<td><textarea cols="20" row="5" name="material.description" id="description">${material.description}</textarea></td>
					</tr> 
					<tr>
						<td align="right"><h4>类型:&nbsp;&nbsp;</h4></td>
						<td>
							<select  validation="required"  name="material.type" id="type" >
								<c:forEach items="${typeList}" var="data">
									<option value="${data.id }" <c:if test="${material.type == data.id}">selected</c:if>>${data.type_name }</option>
								</c:forEach>
							</select>
							<em style="color:red;">*</em>
						</td>
					</tr> 
					<tr>
						<td align="right"><h4>库存:&nbsp;&nbsp;</h4></td>
						<td>
							<input type="text" validation="required,number" name="material.repertory" id="repertory" value="${material.repertory}"/>
							<em style="color:red;">*</em>
						</td>
					</tr> 
					<tr>
						<td align="right"><h4>单位:&nbsp;&nbsp;</h4></td>
						<td>
							<input type="text" validation="required" name="material.unit" id="unit" value="${material.unit}"/>
							<em style="color:red;">*</em>
						</td>
					</tr> 
					<tr>
						<td align="right"><h4>备注:&nbsp;&nbsp;</h4></td>
						<td><textarea cols="40" rows="5" name="material.comments" id="comments">${material.comments}</textarea></td>
					</tr> 
				</tbody>
				<tfoot>
					<tr  class="tableController_bottom">
						<td align="center">
							&nbsp;
						</td>
						<td align="left">
							<a class="button" href="javascript:void(0)" onclick="this.blur(); save();'return false';"><span><img src="${pageContext.request.contextPath }/js/kui/icons/disk.png" align="absmiddle"/>&nbsp;保存</span></a>
							<a class="button" href="javascript:void(0)" onclick="this.blur(); history.go(-1);'return false';"><span><img src="${pageContext.request.contextPath }/js/kui/icons/anticlockwise.png" align="absmiddle"/>&nbsp;返回</span></a>
						</td>
					</tr>
				</tfoot>
		</table>
		</form>
		<script type="text/javascript">
		
			var formId = 'myForm';
			var valid = new KUI.Validation({formId: formId, immediate: true});
			function save(){
				if(valid.validate()){
					document.getElementById(formId).submit();
				}
			}
			var srt;
			function ruleSel(o){
				srt = o.value.split(",");
				<c:forEach items="${ruleList}" var="data" varStatus="i">
					if("${i.index}"==srt[1]){
						var h = '<c:forEach items="${cList[i.index]}" var="data" varStatus="k">'
							+'<select name="rule${k.index}" id="rule${k.index}" style="width:90px;" onchange="ruleSet(this);">'
							+'<option value="">请选择${data.name }</option>'
							+'<c:forEach items="${aList[i.index][k.index]}" var="data1">'
							+'<option value="${data1.att_value }">${data1.att_key }</option>'
							+'</c:forEach></select></c:forEach>';
						document.getElementById("MyAtt").innerHTML=h;
					}
				</c:forEach>
			}
			
			function ruleSet(o){
				var tmp = "";
				var len = document.getElementById("MyAtt").getElementsByTagName("select").length;
				for(var i = 0; i < len; i += 1){
					var str = document.getElementById("rule"+i).value;
					if(str != "") {
						tmp = tmp + str;
						tmp = tmp + "-";
					}
				}
				document.getElementById("materialId").value=tmp;
			}
		</script>
  </body>
</html>
